// ActionScript file
import jpa.domain.LoginUser;

import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
		
		[Bindable]
		public var loginUser:LoginUser;
		private var ro:RemoteObject;

		private function save():void
		{
			loginUser.name = loginUserName.text;
            loginUser.qq=loginUserQQ.text;
            loginUser.enabled=radioGroup.selectedValue;
            loginUser.password=password.text;
			if (loginUser.id == 0)
			{
			ro=Global.getRemoteObject("loginUserController",true,create_resultHandler);
			ro.create(loginUser);
			}
			else
			{
			//Alert.show(radioGroup.selectedValue.toString());
			ro=Global.getRemoteObject("loginUserController",true,update_resultHandler);
			ro.update(loginUser);
			}
				
		}

		private function deleteItem():void
		{
			ro.remove(loginUser);		
		}

		private function create_resultHandler(event:ResultEvent):void
		{
			//carInfo.id = event.result.id;
			dispatchEvent(new LoginUserEvent(LoginUserEvent.CREATED, loginUser));			
		}

		private function update_resultHandler(event:ResultEvent):void
		{
			dispatchEvent(new LoginUserEvent(LoginUserEvent.UPDATED, loginUser));			
		}

		private function remove_resultHandler(event:ResultEvent):void
		{
			dispatchEvent(new LoginUserEvent(LoginUserEvent.DELETED, loginUser));			
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(event.fault.faultDetail);
		}